package com.kaifamiao.handler;

import com.kaifamiao.entity.User;
import org.apache.commons.dbutils.ResultSetHandler;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author lucien-ma
 * @date 2021/10/12
 * @apiNote
 */
public class UserListResultSetHandler implements ResultSetHandler<List<User>> {
    @Override
    public List<User> handle(ResultSet rs) throws SQLException {
        List<User> list = new ArrayList<>();
        while (rs.next()) {
            User user = new User();
            user.setId(rs.getInt("id"));
            user.setUsername(rs.getString("username"));
            user.setPassword(rs.getString("password"));
            list.add(user);
        }
        return list;
    }
}
